package com.bluedot.bank.action;

import java.util.Date;

import com.bluedot.bank.dao.account.Account;
import com.bluedot.bank.dao.account.AccountDao;
import com.bluedot.bank.dao.account.AccountDaoImpl;
import com.bluedot.bank.dao.customer.Customer;
import com.bluedot.bank.dao.customer.CustomerDao;
import com.bluedot.bank.dao.customer.CustomerDaoImpl;
import com.opensymphony.xwork2.ActionSupport;

public class RegAccountAction extends ActionSupport {
	private Account account;
	private String id;

	/**
	 * @return the id
	 */
	public String getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(String id) {
		this.id = id;
	}

	/**
	 * @return the account
	 */
	public Account getAccount() {
		return account;
	}

	/**
	 * @param account the account to set
	 */
	public void setAccount(Account account) {
		this.account = account;
	}
	@Override
	public String execute() throws Exception {
		this.account.setBegin_balance_time(new Date());
		this.account.setBalance(this.account.getBegin_balance());
		this.account.setBalance_time(new Date());
		CustomerDao customerDao=new CustomerDaoImpl();
		Customer customer = customerDao.findById(id);
		this.account.setCustomer(customer);
		AccountDao accountDao=new AccountDaoImpl();
		accountDao.saveOrUpdate(account);
		return SUCCESS;
	}

}
